package yxy.game.pm2.active.module.subordinateclass.weeklycard;

import yxy.cherry.data.bean.actweekcarreward;
import yxy.game.pm2.active.module.actdata.ActDataCenter;
import yxy.game.pm2.bean.Point;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

import java.util.ArrayList;
import java.util.Map;

/**
 * 周卡活动 - 目标任务
 * @author Dell
 *
 */
public class WeeklyTargetTask {

	//bean ------------------------------------------------------------------------
	
	private ArrayList<Integer> ids = new ArrayList<Integer>();			//表格id
	private ArrayList<Integer> unlockids = new ArrayList<Integer>();	//解锁ids
	private ArrayList<Integer> getids = new ArrayList<Integer>();	//获取ids
	
	public ArrayList<Integer> getIds() {
		return ids;
	}
	public void setIds(ArrayList<Integer> ids) {
		this.ids = ids;
	}
	public ArrayList<Integer> getUnlockids() {
		return unlockids;
	}
	public void setUnlockids(ArrayList<Integer> unlockids) {
		this.unlockids = unlockids;
	}
	public ArrayList<Integer> getGetids() {
		return getids;
	}
	public void setGetids(ArrayList<Integer> getids) {
		this.getids = getids;
	}
	
	//func --------------------------------------------------------------------------
	
	public static WeeklyTargetTask create(String playercode) {
		WeeklyTargetTask wtt = new WeeklyTargetTask();
		
		Map<String, actweekcarreward> awcrmap = ActDataCenter.getAllData(actweekcarreward.class, playercode);
		for(actweekcarreward data : awcrmap.values()) {
			wtt.getIds().add(data.getId());
		}
		
		return wtt;
	}
	
	public void reset(String playercode) {
		setIds(new ArrayList<Integer>());
		setGetids(new ArrayList<Integer>());
		setUnlockids(new ArrayList<Integer>());
		
		Map<String, actweekcarreward> awcrmap = ActDataCenter.getAllData(actweekcarreward.class, playercode);
		for(actweekcarreward data : awcrmap.values()) {
			getIds().add(data.getId());
		}
	}
	
	public void refresh() {

	}
	
	public void update(String playercode) {
		//检查解锁
		
		long point = Point.get(playercode, CurrencyType.CT_周卡_货币2,false);
		
		Map<String, actweekcarreward> awcrmap = ActDataCenter.getAllData(actweekcarreward.class, playercode);
		for(int id : getIds()) {
			if(getUnlockids().contains(id)) {
				continue;
			}
			
			actweekcarreward awcr = awcrmap.get(String.valueOf(id));
			if(point >= awcr.getCondition()) {
				getUnlockids().add(id);
			}
		}
	}
	
	public void check(String playercode) {
		if(getUnlockids().size() > getGetids().size()) {
			new TipHandle().updateTip(playercode, TipType.活动_周卡_目标任务奖励, true);
			return;
		}
		new TipHandle().updateTip(playercode, TipType.活动_周卡_目标任务奖励, false);
	}
	
	
}
